package com.lcj.aoch.rule.service.impl;

import com.lcj.aoch.rule.db.dao.CancelRuleDao;
import com.lcj.aoch.rule.service.CancelRuleService;
import com.lcj.common.exception.AochException;
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.IExpressContext;
import java.util.HashMap;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.lcj.aoch.rule.db.pojo.CancelRuleEntity;

@Service
public class CancelRuleServiceImpl implements CancelRuleService {
  @Resource
  private CancelRuleDao cancelRuleDao;
  
  private static final Logger log = LoggerFactory.getLogger(com.lcj.aoch.rule.service.impl.CancelRuleServiceImpl.class);
  
  public HashMap calculateDriverCancelOrder(String status, int cancelNum, int acceptMinute, int waitingMinute, String msg) {
    HashMap<Object, Object> hashMap = new HashMap<>();
    hashMap.put("type", Integer.valueOf(1));
    hashMap.put("key", msg);
    CancelRuleEntity cancelRuleEntity = this.cancelRuleDao.searchCurrentRule(hashMap);
    String rule = cancelRuleEntity.getRule();
    ExpressRunner expressRunner = new ExpressRunner();
    DefaultContext defaultContext = new DefaultContext();
    defaultContext.put("status", status);
    defaultContext.put("cancelNum", Integer.valueOf(cancelNum));
    defaultContext.put("acceptMinute", Integer.valueOf(acceptMinute));
    defaultContext.put("waitingMinute", Integer.valueOf(waitingMinute));
    try {
      HashMap<String, Long> hashMap2 = (HashMap)expressRunner.execute(rule, (IExpressContext)defaultContext, null, true, false);
      hashMap2.put("cancelRuleId", cancelRuleEntity.getId());
      return hashMap2;
    } catch (Exception e) {
      log.error("计算取消订单失败", e);
      throw new AochException("计算取消订单失败");
    } 
  }
  
  public HashMap searchCancelRuleById(long a) {
    return this.cancelRuleDao.searchCancelRuleById(a);
  }
}
